<!DOCTYPE html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>模块管理</title>
    <link href="../../../static/css/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="../../../static/js/jquery.js"></script>
    <script type="text/javascript">
        function tipOpen(moduleId,moduleState) {
            $.ajax({
                type: "post",
                url: "/modules/updateModuleState",
                data: {moduleId:moduleId,moduleState:moduleState},
                dataType: "JSON",
                success: function () {
                    window.location.href = "list";
                },
                error: function (rm) {
                    alert(rm.msg);
                }
            });
        }

        function tipClose() {
            $("#tip").fadeOut(200);
        }

        $(function () {
            var moduleRname = $("#moduleRname").val();
            var pageNum = 1;

            // URL解码
            if (moduleRname) {
                moduleRname = window.decodeURIComponent(moduleRname);
            }
            load(pageNum, moduleRname);
        });

        //分页条件查询
        function load(pageNum, moduleRname) {
            $.ajax({
                type: "post",
                url: "/modules/pageModule",
                data: {pageNum: pageNum, moduleRname: moduleRname},
                dataType: "JSON",
                async: true,
                success: function (rm) {
                    let list = rm.data.data;
                    let str = '<thead>\n' +
                        '            <tr>\n' +
                        '                <th>序号</th>\n' +
                        '                <th>模块名称</th>\n' +
                        '                <th>父模块</th>\n' +
                        '                <th>URL</th>\n' +
                        '                <th>状态</th>\n' +
                        '                <th>操作</th>\n' +
                        '            </tr>\n' +
                        '            </thead>\n' +
                        '<tbody>';
                    for (let i = 0; i < list.length; i++) {
                        let status;
                        if (list[i].moduleState == 1) {
                            status = "正常";
                        } else if (list[i].moduleState == 2) {
                            status = "禁用";
                        } else {
                            status = "";
                        }
                        str += '        <tr>\n' +
                            '          <td>' + (i + 1) + '</td>\n' +
                            '          <td>' + list[i].moduleRname + '</td>\n' +
                            '          <td>' + list[i].modulePname + '</td>\n' +
                            '          <td>' + list[i].moduleMurl + '</td>\n' +
                            '          <td>' + status + '</td>\n' +
                            '          <td>\n' +
                            '            <a href="moduleView" class="tablelink" onclick="moduleView(' + list[i].moduleId + ')">查看详情</a>\n'+
                            '            <a href="moduleUpdate" class="tablelink" onclick="moduleUpdate(' + list[i].moduleId + ')">修改</a>\n';
                        if (list[i].moduleState == 1) {
                            str += '            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen(' + list[i].moduleId + ',' + list[i].moduleState + ')">禁用</a>\n';
                        } else {
                            str += '            <a href="javascript:void(0)" class="tablelink" onclick="tipOpen(' + list[i].moduleId + ',' + list[i].moduleState + ')">恢复</a>\n';
                        }

                        str += ' </td>\n' +
                            '</tr>';
                    }
                    str +=  '</tbody>';
                    $("#moduleList").html(str);

                    $("#totalCount").html(rm.data.totalCount);
                    $("#pageNum").html(rm.data.pageNum);

                    let begin = rm.data.pageNum - 5;
                    let end = rm.data.pageNum + 4;
                    if (begin < 1) {
                        begin = 1;
                        if (rm.data.totalPage < 10) {
                            end = rm.data.totalPage;
                        } else {
                            end = 10;
                        }
                    }

                    if (end > rm.data.totalPage) {
                        end = rm.data.totalPage;
                        if (begin < 0) {
                            begin = 1;
                        } else {
                            if (rm.data.totalPage > 10) {
                                begin = rm.data.totalPage - 9;
                            } else {
                                begin = 1;
                            }
                        }
                    }


                    let index = '<li class="paginItem" onclick="javascript:load(1,\'' + moduleRname + '\')"><a href="javascript:void(0)">首页</a></li>';
                    let beforeNum = rm.data.pageNum - 1;
                    if (beforeNum < 1) {
                        beforeNum = 1;
                    }
                    index += '<li class="paginItem" onclick="javascript:load(' + beforeNum + ',\'' + moduleRname + '\')"><a href="javascript:void(0)"><span class="pagepre"></span></a></li>';
                    for (let i = begin; i <= end; i++) {
                        if (i == rm.data.pageNum) {
                            index += '<li class="paginItem current" onclick="javascript:load(' + i + ',\'' + moduleRname + '\')"><a href="javascript:void(0)">' + i + '</a></li>';
                        } else {
                            index += '<li class="paginItem" onclick="javascript:load(' + i + ',\'' + moduleRname + '\')" ><a href="javascript:void(0)">' + i + '</a></li>';
                        }
                    }
                    let nextNum = rm.data.pageNum + 1;
                    if (nextNum >= rm.data.totalPage) {
                        nextNum = rm.data.totalPage;
                    }
                    index += '<li class="paginItem" onclick="javascript:load(' + nextNum + ',\'' + moduleRname + '\')"><a href="javascript:void(0)"><span class="pagenxt"></span></a></li>';
                    index += '<li class="paginItem" onclick="javascript:load(' + rm.data.totalPage + ',\'' + moduleRname + '\')" ><a href="javascript:void(0)">末页</a></li>';

                    $("#paginList").html(index);
                }
                ,
                error: function (rm) {
                    alert(rm.msg)
                }
            });
        }

        //详情传值
        function moduleView(moduleId) {
            localStorage.setItem("sysmoduleId2", JSON.stringify(moduleId));
        }

        //修改传值
        function moduleUpdate(moduleId) {
            localStorage.setItem("sysmoduleId", JSON.stringify(moduleId));
        }

        //点击查询
        function pageModule() {
            var moduleRname = $("#moduleRname").val();
            var pageNum = 1;
            load(pageNum,moduleRname);
        }
    </script>
</head>

<body>
<div class="place"><span>位置：</span>
    <ul class="placeul">
        <li><a href="../modules/list">系统管理</a></li>
        <li><a href="../modules/list">模块管理</a></li>
    </ul>
</div>
<div class="rightinfo">
    <form action="" method="post">
        <ul class="tools">
            <li><label>模块名称:</label>
                <input type="text" id="moduleRname" name="moduleRname"/>
            </li>

            <li class="subBut" onclick="pageModule()"><img src="../../../static/images/t06.png"/>查询</li>
            <li class="subBut" onclick="window.location.href='moduleAdd'"><img src="../../../static/images/t01.png"/>添加
            </li>
        </ul>
        <table class="tablelist" id="moduleList">
            <thead>
            <tr>
                <th>序号</th>
                <th>模块名称</th>
                <th>父模块</th>
                <th>URL</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>1</td>
                <td>系统管理</td>
                <td>无</td>
                <td>#</td>
                <td>正常</td>
                <td>
                    <a href="moduleUpdate.html" class="tablelink">修改</a>
                    <a href="javascript:void(0);" class="tablelink" onclick="tipOpen('是否确禁用此模块？')">禁用</a>
                </td>
            </tr>
            <tr>
                <td>2</td>
                <td>用户管理</td>
                <td>系统管理</td>
                <td>sys/users/userList.html</td>
                <td>正常</td>
                <td>
                    <a href="moduleUpdate.html" class="tablelink">修改</a>
                    <a href="javascript:void(0);" class="tablelink" onclick="tipOpen('是否确禁用此模块？')">禁用</a>
                </td>
            </tr>
            <tr>
                <td>3</td>
                <td>部门管理</td>
                <td>系统管理</td>
                <td>sys/dept/deptList.html</td>
                <td>正常</td>
                <td>
                    <a href="moduleUpdate.html" class="tablelink">修改</a>
                    <a href="javascript:void(0);" class="tablelink" onclick="tipOpen('是否确禁用此模块？')">禁用</a>
                </td>
            </tr>
            <tr>
                <td>3</td>
                <td>测试管理</td>
                <td>无</td>
                <td>#</td>
                <td>禁用</td>
                <td>
                    <a href="moduleUpdate.html" class="tablelink">修改</a>
                    <a href="javascript:void(0);" class="tablelink" onclick="tipOpen('是否确启用此模块？')">启用</a>
                </td>
            </tr>
            </tbody>
        </table>
        <div class="pagin">
            <div class="message">共<i class="blue" id="totalCount">1256</i>条记录，当前显示第&nbsp;<i class="blue" id="pageNum">2&nbsp;</i>页</div>
            <ul class="paginList" id="paginList">
<!--                <li class="paginItem"><a href="javascript:;"><span class="pagepre"></span></a></li>-->
<!--                <li class="paginItem"><a href="javascript:;">1</a></li>-->
<!--                <li class="paginItem current"><a href="javascript:;">2</a></li>-->
<!--                <li class="paginItem"><a href="javascript:;">3</a></li>-->
<!--                <li class="paginItem"><a href="javascript:;">4</a></li>-->
<!--                <li class="paginItem"><a href="javascript:;">5</a></li>-->
<!--                <li class="paginItem more"><a href="javascript:;">...</a></li>-->
<!--                <li class="paginItem"><a href="javascript:;">10</a></li>-->
<!--                <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
            </ul>
        </div>
    </form>
    <!-- 提示框 -->
    <div id="tip" class="tip">
        <div class="tiptop"><span>提示信息</span><a onclick="tipClose()"></a></div>
        <div class="tipinfo"><span><img src="../../../static/images/ticon.png"/></span>
            <div class="tipright">
                <p></p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite></div>
        </div>
        <div class="tipbtn">
            <input name="" type="button" class="sure" value="确定" onclick="tipClose()"/>
            &nbsp;
            <input name="" type="button" class="cancel" value="取消" onclick="tipClose()"/>
        </div>
    </div>
</div>
<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
</body>
